<template>
    <am-list :header="title">
        <am-picker
            :title="placeholder"
            :data="data"
            v-model="val"
            @ok="onOK"
        >
            <am-list-item
                slot-scope="{ extra, show }"
                :title="label"
                :extra="extra"
                @click="show"
            >

            </am-list-item>

        </am-picker>
    </am-list>
</template>

<script>

    import AmList from "../../weex-amui/packages/am-list/index";
    import AmPicker from "../../weex-amui/packages/am-picker/index";
    import AmListItem from "../../weex-amui/packages/am-list/item";
    export default {
        name: "yx-radio",
        components: {AmListItem, AmPicker, AmList},
        model: {
            prop: 'value',
            event: 'ok'
        },
        props: {
            title: {
              type: String,
              default: ''
            },
            placeholder: {
              type: String,
                default: ''
            },
            data: {
                type: [Object],
                default: []
            },
            label: {
                type: String,
                default: ''
            },
            value: {
                type: [String,Number],
                default: null
            }

        },
        data (){
            return {
                val: [],
                isTargetEvent:false
            }
        },
        methods: {
            onOK (value, label) {
                this.isTargetEvent = true
                console.log('ok', value, label)
                this.$emit('ok', this.val[0])
            }
        },
        mounted (){
            this.val= [this.value]
        },
        watch: {
            value (val){
                if (this.isTargetEvent) {
                    this.value = val

                }else {
                    this.val = [this.value]
                }

                this.isTargetEvent = false;
            }
        }
    }
</script>

<style scoped>

</style>
